import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router'
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
NProgress.configure({
    showSpinner: true,
    easing: 'ease',
})
const routes: RouteRecordRaw[] = [
    {
        name: 'main',
        path: '/',
        component: () => import('@/views/Main.vue'),
        redirect: 'home',
        children: [
            {
                name: 'home',
                path: 'home',
                component: () => import('@/views/Welcome.vue'),
                meta: {
                    title: '首页',
                },
            },
            {
                name: 'user',
                path: '/system/user',
                component: () => import('@/views/UserManage.vue'),
                meta: {
                    title: '用户管理',
                },
            },
            {
                name: 'menu',
                path: '/system/menu',
                component: () => import('@/views/MenuManage.vue'),
                meta: {
                    title: '菜单管理',
                },
            },
            {
                name: 'role',
                path: '/system/role',
                component: () => import('@/views/RoleManage.vue'),
                meta: {
                    title: '角色管理',
                },
            },
            {
                name: 'dept',
                path: '/system/dept',
                component: () => import('@/views/DeptManage.vue'),
                meta: {
                    title: '部门管理',
                },
            },
        ],
    },
    {
        name: 'login',
        path: '/login',
        component: () => import('@/views/Login.vue'),
        meta: {
            title: '登陆页面',
        },
    },
]

const router = createRouter({
    history: createWebHistory(),
    routes,
})

router.beforeEach((to, from) => {
    document.title = (to.meta.title as string) || '未知页面'
    NProgress.start()
})

router.afterEach((to, from) => {
    NProgress.done()
})

export default router
